<template>
  <div>
    <el-dialog
      :visible.sync="showDialog"
      append-to-body
      :close-on-click-modal="false"
      @close="close"
      destroy-on-close="true"
      width="50%"
    >
      <div class="showbox">
        <div :style="this.showoff">
          <h3>承运商报价</h3>
          <el-form
            :model="Form"
            ref="Form"
            label-width="120px"
            class="demo-ruleForm"
            disabled
          >
            <el-form-item label="船公司">
              <el-input v-model="Form.shippingCompany"></el-input>
            </el-form-item>
            <el-form-item label="海运费（USD）">
              <el-input v-model="Form.shippingFee"></el-input>
            </el-form-item>
            <el-form-item label="港杂费（CNY）">
              <el-input v-model="Form.portCharges"></el-input>
            </el-form-item>
            <el-form-item label="船期_ETD">
              <el-date-picker
                v-model="Form.shippingDateETD"
                type="date"
                style="width: 100%"
              >
              </el-date-picker>
            </el-form-item>
            <el-form-item label="船期_ETA">
              <el-date-picker
                v-model="Form.scheduleEta"
                type="date"
                style="width: 100%"
              >
              </el-date-picker>
            </el-form-item>
            <el-form-item label="起运港(箱使/天)">
              <el-input v-model="Form.departurePortBoxAngel"></el-input>
            </el-form-item>
            <el-form-item label="目的港(箱使/天)">
              <el-input v-model="Form.destinationPortBoxAngel"></el-input>
            </el-form-item>
            <el-form-item label="是否直达">
              <el-input v-model="Form.isItDirect"></el-input>
            </el-form-item>
          </el-form>
        </div>
        <div style="width: 60%">
          <h3>调整报价</h3>
          <el-form
            :model="ruleForm"
            :rules="rules"
            ref="ruleForm"
            label-width="120px"
            class="demo-ruleForm"
          >
            <el-form-item label="船公司" prop="shippingCompany">
              <el-input v-model="ruleForm.shippingCompany"></el-input>
            </el-form-item>
            <el-form-item label="海运费（USD）" prop="shippingFee">
              <el-input v-model.number="ruleForm.shippingFee"></el-input>
            </el-form-item>
            <el-form-item label="港杂费（CNY）" prop="portCharges">
              <el-input v-model.number="ruleForm.portCharges"></el-input>
            </el-form-item>
            <el-form-item label="船期_ETD" prop="shippingDateETD">
              <el-date-picker
                v-model="ruleForm.shippingDateETD"
                type="date"
                placeholder="选择船期_ETD"
                style="width: 100%"
              >
              </el-date-picker>
            </el-form-item>
            <el-form-item label="船期_ETA" prop="scheduleEta">
              <el-date-picker
                v-model="ruleForm.scheduleEta"
                type="date"
                placeholder="选择船期_ETA"
                style="width: 100%"
              >
              </el-date-picker>
            </el-form-item>
            <el-form-item label="起运港(箱使/天)" prop="departurePortBoxAngel">
              <el-input v-model="ruleForm.departurePortBoxAngel"></el-input>
            </el-form-item>
            <el-form-item label="目的港(箱使/天)" prop="destinationPortBoxAngel">
              <el-input v-model="ruleForm.destinationPortBoxAngel"></el-input>
            </el-form-item>
            <el-form-item label="是否直达" prop="isItDirect">
              <el-input v-model="ruleForm.isItDirect"></el-input>
            </el-form-item>
          </el-form>
        </div>
      </div>
      <el-form ref="descForm" :model="form" label-width="80px">
        <el-form-item label="报价说明">
          <el-input
            type="textarea"
            v-model="descForm.quoteDescription"
          ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button @click="close()">取消</el-button>
        <el-button @click="submit('ruleForm')" type="primary">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { deepClone } from "@/util/util.js";
export default {
  name: "historicalBarrier",
  props: {
    modifyData: {},
    identity: {},
  },
  data() {
    return {
      showDialog: false,
      callback: () => {},
      form: {},
      showoff: {},
      transmission: {},
      descForm: {
        quoteDescription: "",
      },
      ruleForm: {
        shippingCompany: "",
        shippingFee: "",
        portCharges: "",
        shippingDateETD: "",
        scheduleEta: "",
        departurePortTime: "",
        destinationPortTime: "",
        isItDirect: "",
        quoteDescription: "",
      },
      Form: {
        shippingCompany: "",
        shippingFee: "",
        portCharges: "",
        shippingDateETD: "",
        scheduleEta: "",
        departurePortTime: "",
        destinationPortTime: "",
        isItDirect: "",
      },
      rules: {
        shippingCompany: [
          { required: true, message: "请输入船公司", trigger: "blur" },
        ],
        shippingFee: [
          { required: true, message: "请输入海运费", trigger: "blur" },
          { type: "number", message: "必须为数字值" },
        ],
        portCharges: [
          { required: true, message: "请输入港杂费", trigger: "blur" },
          { type: "number", message: "必须为数字值" },
        ],
        shippingDateETD: [
          {
            type: "date",
            required: true,
            message: "请输入船期_ETD",
            trigger: "change",
          },
        ],
        scheduleEta: [
          {
            type: "date",
            required: true,
            message: "请输入船期_ETA",
            trigger: "change",
          },
        ],
        departurePortBoxAngel: [
          { required: true, message: "请输入起运港(箱使/天)", trigger: "blur" },
        ],
        destinationPortBoxAngel: [
          { required: true, message: "请输入目的港(箱使/天)", trigger: "blur" },
        ],
        isItDirect: [
          { required: true, message: "请输入是否直达", trigger: "blur" },
        ],
      },
    };
  },
  watch: {
    modifyData() {
      this.transmission = this.modifyData;
      this.Form = { ...this.modifyData };
      this.isManagement = this.identity.isManagement;
      this.showoff = this.identity.showoff;
    },
  },
  methods: {
    open(row, { callback }) {
      this.callback = callback;
      this.showDialog = true;
    },
    close() {
      this.showDialog = false;
      this.Form = { ...this.modifyData };
      this.ruleForm = {
        shippingCompany: "",
        shippingFee: "",
        portCharges: "",
        shippingDateETD: "",
        scheduleEta: "",
        departurePortTime: "",
        destinationPortTime: "",
        isItDirect: "",
        quoteDescription: "",
      };
    },

    submit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          let inquiryId = {
            ...this.transmission,
            ...this.ruleForm,
            ...this.descForm,
          };
          this.callback(deepClone(inquiryId));
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
  },
};
</script>

<style>
.showbox {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: space-between;
}
</style>
